<template>
    <el-dialog
            v-model="isVisible"
            width="30%"
            :title="title"
            :destroy-on-close="true"
            :close-on-click-modal="false"
    >
        <el-form :model="formData" ref="searchFormRef" label-width="120px">
            <el-row :gutter="16" type="flex" justify="center" class="flex-wrap-wrap">
                <el-col :span="18">
                    <el-form-item label="字典标识：">
                        <el-input disabled placeholder="请输入" v-model="formData.code"/>
                    </el-form-item>
                </el-col>
                <el-col :span="18">
                    <el-form-item label="显示标签：">
                        <el-input placeholder="请输入显示标签" v-model="formData.label"/>
                    </el-form-item>
                </el-col>
                <el-col :span="18">
                    <el-form-item label="字典码值：">
                        <el-input placeholder="请输入字典码值" v-model="formData.value" maxlength="20"/>
                    </el-form-item>
                </el-col>
                <el-col :span="18">
                    <el-form-item label="排序：">
                        <el-input-number v-model="formData.sort" :precision="0"  :min="1" />
                        <!--<el-input type="number" min="1" placeholder="请输入字典码值" v-model="formData.sort" maxlength="20"/>-->
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row justify="center">
                <el-button @click="isVisible = false" type="info" plain icon="Close" class="mr-100px">取消</el-button>
                <el-button @click="service.saveOrUpdate(formData).success(props.saveSuccess).error(props.saveError).request()" type="primary" icon="Check" >保存</el-button>
            </el-row>
        </el-form>
    </el-dialog>
</template>
<script lang="ts" setup>
    import service, {DictItem} from "@/api/sys/SysDictItemApi";
    import {defineExpose, ref, defineEmits, defineProps, watch} from "vue";
    import MsgUtils from "@/common/utils/MsgUtils";

    let formData = ref<DictItem>()
    let title = ref<string>('')
    let isVisible = ref<boolean>(false)

    let props = defineProps(['saveSuccess', 'saveError']);

    const open = (type: 'create' | 'edit' | 'detail', data?: any) => {
        if (type == "create") {
            title.value = '新增';
            formData.value = JSON.parse(JSON.stringify(data));
            isVisible.value = true;
        }
        if (type == "detail") {
            title.value = '查看';
            formData.value = JSON.parse(JSON.stringify(data));
            isVisible.value = true;
        }
        if (type == "edit") {
            title.value = '编辑';
            formData.value = JSON.parse(JSON.stringify(data));
            isVisible.value = true;
        }
    }
    const close = () => {
        isVisible.value = false;
    }
    defineExpose({open, close})

</script>
<style lang="scss" scoped>
</style>

